package util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Random;

public class TotalClass {

	/**
	 *@author qingyu zhang
	 *@function:
	 *2011-4-4
	 *下午02:43:43
	 *zzClub
	 *util
	 */
	// 数据库连接
	private  Connection conn = null;
	// st对象
	private  PreparedStatement pt = null;

	private  Statement st = null;
	// 结果集
	private  ResultSet rs = null;
	// 成功失败标志
	private boolean flag = false;
	// 要执行的语句
	private String sql = "";
	
	public  ResultSet getResult(String sql){
		try {
			pt = getConn().prepareStatement(sql);
			rs = pt.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			return rs;
		}
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:when you add  or delete or modify ref the method 
	 * @param sql
	 * @return
	 *2011-4-5
	 *下午03:59:49
	 *zzClub
	 *util
	 *boolean
	 */
	public  boolean operatorObject(String sql){
		boolean bo = false;
		conn = getConn();
		try {
			pt = conn.prepareStatement(sql);
			bo = pt.execute();
			bo = true;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			bo = false;
		}
		return bo ;
		
	}
	//得到数据库的连接
	public  Connection getConn(){
		try {
			conn = ConnectDB.getSqlServerConnection();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			ConnectDB.closeSqlConnection();
			return conn;
		}
	}
	public Statement getStatement(){
		try {
			st = getConn().createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			ConnectDB.closeSqlConnection();
			return st;
		}
	}
	/**
	 * 
	 *@author qingyu zhang
	 *@function:得到一个六位数
	 * @return
	 *2011-4-6
	 *下午03:55:15
	 *zzClub
	 *util
	 *String
	 */
	public static String getNum(){
		String checkCodeStr="";
		Random rd=new Random();
		for(int i=0;i<6;i++){
			checkCodeStr+=rd.nextInt(9);
		}
		return checkCodeStr;
	}
}
